package com.happyface.itemtouchhelper;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {

    private RecyclerView recyclerView;
    private ImageView imageView;
    private ModuleData moduleData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        initView();
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
//        imageView = (ImageView) findViewById(R.id.iv_close);
        GridLayoutManager manager = new GridLayoutManager(this, 4);
        recyclerView.setLayoutManager(manager);
        ItemTouchHelperCallBack callBack = new ItemTouchHelperCallBack();
        ItemTouchHelper touchHelper = new ItemTouchHelper(callBack);
        touchHelper.attachToRecyclerView(recyclerView);
        final ModuleSortAdapter adapter = new ModuleSortAdapter(this, moduleData, 1, touchHelper);
        manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                int viewType = adapter.getItemViewType(position);
                return viewType == ModuleSortAdapter.TYPE_MY_MODULE || viewType == ModuleSortAdapter.TYPE_MORE_MODULE ? 1 : 4;
            }
        });
        recyclerView.setAdapter(adapter);
    }

    private void initData() {
        moduleData = new ModuleData();
        List<ModuleData.ModuleInfo> list = new ArrayList<>();
        List<ModuleData.ModuleInfo> list1 = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            ModuleData.ModuleInfo moduleInfo = new ModuleData.ModuleInfo();
            moduleInfo.setModel_id("i");
            moduleInfo.setModel_name("我的板块" + i);
            list.add(moduleInfo);
        }
        for (int i = 0; i < 10; i++) {
            ModuleData.ModuleInfo moduleInfo1 = new ModuleData.ModuleInfo();
            moduleInfo1.setModel_id("i");
            moduleInfo1.setModel_name("更多板块" + i);
            list1.add(moduleInfo1);
        }
        moduleData.setUser_model_list(list);
        moduleData.setMore_model_list(list1);
    }
}
